package com.app.megaprosoft.DB;

import java.sql.*;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class Ar {
	Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
    
    SQLiteDBClass myDb;
    SQLiteDatabase db;
    private static final String TABLE_ArFF = "_ArFF";
    
    Context context;
	 public Context getContext() {
		return context;
	 }

	 public void setContext(Context context) {
		this.context = context;
	 }
	 
	private String ArCode,ArTitle,ArName,ArNickName,ArAddr1,ArAddr2,TumbolCode,AmpurCode,ProvinceCode,BillAdd1,BillAdd2,ArGroupCode,BrokerCode,Payment,Terms;
	private String Telephone,Fax,Mobile,FFSaleCode,FFUserCode,ContactDate,Remark,IsDisplayWeightDoc,PicPath,FFCashier,ContractPerson,CarBandOID,VehicleRegistration,
					CarGenerationOID,
					CarType,
					ColorOID,
					CarSize,
					CompanyOID,
					CarGroup;
	
	private int CreditDay,ArStatus,IsPromotion,IsRound,BrokerStatus,IsCredit,IsCreditItem,CreditItemDay;
	private float DebtLimitBal,DebtLimit1,DebtAmount ;
	private String OID,UsrOpt,IsActive,IsDeleted;
	
	private String StrParamArGroupMainCode;
	private String StrParamArGroupCode;
	private String StrParamArName="";
    
	
	public Ar() {
		ArCode=ArTitle=ArName=ArNickName=ArAddr1=ArAddr2=TumbolCode=AmpurCode=ProvinceCode=BillAdd1=BillAdd2=ArGroupCode=BrokerCode=Payment=Terms="";
		Telephone=Fax=Mobile=FFSaleCode=FFUserCode=ContactDate=Remark=IsDisplayWeightDoc=PicPath=FFCashier=ContractPerson="";
		ArStatus=CreditDay=IsPromotion=BrokerStatus=0;
		DebtLimitBal=DebtLimit1=DebtAmount=0.0F ;
		IsRound=IsCredit=IsCreditItem=CreditItemDay=0;
    }
	
		public Ar(
				String OID,
	    		String UsrOpt,
	    		String IsActive,
	    		String IsDeleted,
				String ArCode,
				String ArTitle,
				String ArName,
				String ArNickName,
				String ArAddr1,
				String ArAddr2,
				String TumbolCode,
				String AmpurCode,
				String ProvinceCode,
				String BillAdd1,
				String BillAdd2,
				String ArGroupCode,
				String BrokerCode,
				String Payment,
				String Terms,
				String Telephone,
				String Fax,
				String Mobile,
				String FFSaleCode,
				String FFUserCode,
				String ContactDate,
				String Remark,
				String IsDisplayWeightDoc,
				String PicPath,
				String FFCashier,
				String ContractPerson,
				int CreditDay,
				int ArStatus,
				int IsPromotion,
				int IsRound,
				int BrokerStatus,
				int IsCredit,
				int IsCreditItem,
				int CreditItemDay,
				float DebtLimitBal,
				float DebtLimit1,
				float DebtAmount,
				String CarBandOID,
				String VehicleRegistration,
				String CarGenerationOID,
				String CarType,
				String ColorOID,
				String CarSize,
				String CompanyOID,
				String CarGroup
		)
		
		{
			this.OID = OID;
	    	this.UsrOpt = UsrOpt;
	    	this.IsActive = IsActive;
	    	this.IsDeleted = IsDeleted;
	    	this.ArCode = ArCode;
	    	this.ArTitle = ArTitle;
	    	this.ArName = ArName;
	    	this.ArNickName = ArNickName;
	    	this.ArAddr1 = ArAddr1;
	    	this.ArAddr2 = ArAddr2;
	    	this.TumbolCode = TumbolCode;
	    	this.AmpurCode = AmpurCode;
	    	this.ProvinceCode = ProvinceCode;
	    	this.BillAdd1 = BillAdd1;
	    	this.BillAdd2 = BillAdd2;
	    	this.ArGroupCode = ArGroupCode;
	    	this.BrokerCode = BrokerCode;
	    	this.Payment = Payment;
	    	this.Terms = Terms;
	    	this.Telephone = Telephone;
	    	this.Fax = Fax;
	    	this.Mobile = Mobile;
	    	this.FFSaleCode = FFSaleCode;
	    	this.FFUserCode = FFUserCode;
	    	this.ContactDate = ContactDate;
	    	this.Remark = Remark;
	    	this.IsDisplayWeightDoc = IsDisplayWeightDoc;
	    	this.PicPath = PicPath;
	    	this.FFCashier = FFCashier;
	    	this.ContractPerson = ContractPerson;
	    	this.CreditDay = CreditDay; 
	    	this.ArStatus = ArStatus;
	    	this.IsPromotion = IsPromotion;
	    	this.IsRound = IsRound;
	    	this.BrokerStatus = BrokerStatus;
	    	this.IsCredit = IsCredit;
	    	this.IsCreditItem = IsCreditItem;
	    	this.CreditItemDay = CreditItemDay;
	    	this.DebtLimitBal = DebtLimitBal;
	    	this.DebtLimit1 = DebtLimit1;
	    	this.DebtAmount  = DebtAmount;
	    	this.CarBandOID = CarBandOID;
	    	this.VehicleRegistration = VehicleRegistration;
	    	this.CarGenerationOID = CarGenerationOID;
	    	this.CarType = CarType;
	    	this.ColorOID = ColorOID;
	    	this.CarSize = CarSize; 
	    	this.CompanyOID = CompanyOID;
	    	this.CarGroup = CarGroup;
	    }
		
		
		//--------------Parameter----------//
		
		public String getStrParamArGroupMainCode() {
			return StrParamArGroupMainCode;
		}

		public String getCarGroup() {
			return CarGroup;
		}

		public void setCarGroup(String carGroup) {
			CarGroup = carGroup;
		}

		public String getCompanyOID() {
			return CompanyOID;
		}

		public void setCompanyOID(String companyOID) {
			CompanyOID = companyOID;
		}

		public String getCarGenerationOID() {
			return CarGenerationOID;
		}

		public void setCarGenerationOID(String carGenerationOID) {
			CarGenerationOID = carGenerationOID;
		}

		public String getCarType() {
			return CarType;
		}

		public void setCarType(String carType) {
			CarType = carType;
		}

		public String getColorOID() {
			return ColorOID;
		}

		public void setColorOID(String colorOID) {
			ColorOID = colorOID;
		}

		public String getCarSize() {
			return CarSize;
		}

		public void setCarSize(String carSize) {
			CarSize = carSize;
		}

		public void setStrParamArGroupMainCode(String strParamArGroupMainCode) {
			StrParamArGroupMainCode = strParamArGroupMainCode;
		}

		public String getStrParamArGroupCode() {
			return StrParamArGroupCode;
		}

		public void setStrParamArGroupCode(String strParamArGroupCode) {
			StrParamArGroupCode = strParamArGroupCode;
		}

		public String getStrParamArName() {
			return StrParamArName;
		}

		public void setStrParamArName(String strParamArName) {
			StrParamArName = strParamArName;
		}

		public String getCarBandOID() {
			return CarBandOID;
		}

		public void setCarBandOID(String carBandOID) {
			CarBandOID = carBandOID;
		}

		public String getVehicleRegistration() {
			return VehicleRegistration;
		}

		public void setVehicleRegistration(String vehicleRegistration) {
			VehicleRegistration = vehicleRegistration;
		}

		public String getOID() {
			return OID;
		}

		public void setOID(String oID) {
			OID = oID;
		}

		public String getUsrOpt() {
			return UsrOpt;
		}

		public void setUsrOpt(String usrOpt) {
			UsrOpt = usrOpt;
		}

		public String getIsActive() {
			return IsActive;
		}

		public void setIsActive(String isActive) {
			IsActive = isActive;
		}

		public String getIsDeleted() {
			return IsDeleted;
		}

		public void setIsDeleted(String isDeleted) {
			IsDeleted = isDeleted;
		}
		
		public void setArCode(String ArCode)
		{
			this.ArCode = ArCode;
		}
		public void setArTitle(String ArTitle)
		{
			this.ArTitle = ArTitle;
		}
		public void setArName(String ArName)
		{
			this.ArName = ArName;
		}
		public void setArNickName(String ArNickName)
		{
			this.ArNickName = ArNickName;
		}
		public void setArAddr1(String ArAddr1)
		{
			this.ArAddr1 = ArAddr1;
		}
		public void setArAddr2(String ArAddr2)
		{
			this.ArAddr2 = ArAddr2;
		}
		public void setTumbolCode(String TumbolCode)
		{
			this.TumbolCode = TumbolCode;
		}
		public void setAmpurCode(String AmpurCode)
		{
			this.AmpurCode = AmpurCode;
		}
		public void setProvinceCode(String ProvinceCode)
		{
			this.ProvinceCode = ProvinceCode;
		}
		public void setBillAdd1(String BillAdd1)
		{
			this.BillAdd1 = BillAdd1;
		}
		public void setBillAdd2(String BillAdd2)
		{
			this.BillAdd2 = BillAdd2;
		}
		public void setArGroupCode(String ArGroupCode)
		{
			this.ArGroupCode = ArGroupCode;
		}
		public void setTelephone(String Telephone)
		{
			this.Telephone = Telephone;         
		}
		public void setFax(String Fax)
		{
			this.Fax = Fax;
		}
		public void setMobile(String Mobile)
		{
			this.Mobile = Mobile;
		}
		public void setFFSaleCode(String FFSaleCode)
		{
			this.FFSaleCode = FFSaleCode;
		}
		public void setFFUserCode(String FFUserCode)
		{
			this.FFUserCode = FFUserCode;
		}
		
		public void setContactDate(String ContactDate)
		{
			this.ContactDate = ContactDate;
		}
		public void setCreditDay(String CreditDay)
		{
			this.CreditDay = Integer.parseInt(CreditDay);
		}	
		
		public void setArStatus(String ArStatus)
		{
			this.ArStatus= Integer.parseInt(ArStatus);
		}
		
		
		public void setRemark(String Remark)
		{
			this.Remark = Remark;
		}
		public void setIsDisplayWeightDoc(String IsDisplayWeightDoc)
		{
			this.IsDisplayWeightDoc = IsDisplayWeightDoc;
		}
		public void setPicPath(String PicPath)
		{
			this.PicPath = PicPath;
		}
		public void setDebtLimitBal(String DebtLimitBal)
		{
			this.DebtLimitBal = Float.valueOf(DebtLimitBal).floatValue();
		}	
		public void setDebtLimit1(String DebtLimit1)
		{
			this.DebtLimit1 = Float.valueOf(DebtLimit1).floatValue();
		}	
		public void setDebtAmount(String DebtAmount)
		{
			this.DebtAmount = Float.valueOf(DebtAmount).floatValue();
		}	
		public void setIsPromotion(String IsPromotion)
		{
			this.IsPromotion= Integer.parseInt(IsPromotion);
		}	
		public void setIsRound(String IsRound)
		{
			this.IsRound = Integer.parseInt(IsRound);
		}	
		public void setFFCashier(String FFCashier)
		{
			this.FFCashier = FFCashier;
		}
		public void setBrokerCode(String BrokerCode)
		{
			this.BrokerCode = BrokerCode;
		}
		public void setBrokerStatus(String BrokerStatus)
		{
			this.BrokerStatus = Integer.valueOf(BrokerStatus).intValue();
		}
		public void setContractPerson(String ContractPerson)
		{
			this.ContractPerson = ContractPerson;
		}	
		public void setIsCredit(String IsCredit)
		{
			this.IsCredit = Integer.parseInt(IsCredit);
		}
		public void setIsCreditItem(String IsCreditItem)
		{
			this.IsCreditItem = Integer.parseInt(IsCreditItem);
		}
		public void setCreditItemDay(String CreditItemDay)
		{
			this.CreditItemDay = Integer.parseInt(CreditItemDay);
		}
		 public void setPayment(String Payment)
		{
			this.Payment = Payment;
		}
		 public void setTerms(String Terms)
		{
			this.Terms = Terms;
		}

		//////////////////  Get Function ////////////////
		public String getArCode()
		{
			return this.ArCode;
		}
		public String getArTitle()
		{
			return this.ArTitle;
		}
		public String getArName()
		{
			return this.ArName;
		}
		public String getArNickName()
		{
			return this.ArNickName;
		}
		public String getArAddr1()
		{
			return this.ArAddr1;
		}
		public String getArAddr2()
		{
			return this.ArAddr2;
		}
		public String getTumbolCode()
		{
			return this.TumbolCode;
		}
		public String getAmpurCode()
		{
			return this.AmpurCode;
		}
		public String getProvinceCode()
		{
			return this.ProvinceCode;
		}
		public String getBillAdd1()
		{
			return this.BillAdd1;
		}
		public String getBillAdd2()
		{
			return this.BillAdd2;
		}
		public String getArGroupCode()
		{
			return this.ArGroupCode;
		}
		public String getTelephone()
		{
			return this.Telephone;
		}
		public String getFax()
		{
			return this.Fax;
		}
		public String getMobile()
		{
			return this.Mobile;	
		}
		public String getFFSaleCode()
		{
			return this.FFSaleCode;	
		}
		public String getFFUserCode()
		{
			return this.FFUserCode;	
		}
		public String getContactDate()
		{
			return this.ContactDate;
		}
		public int getCreditDay()
		{
			return this.CreditDay;
		}
		public String getRemark()
		{
			return this.Remark;
		}
		public String getIsDisplayWeightDoc()
		{
			return this.IsDisplayWeightDoc;
		}
		public String getPicPath()
		{
			return this.PicPath;
		}
		public int getArStatus()
		{
			return this.ArStatus;
		}
		public float getDebtLimitBal()
		{
		    return this.DebtLimitBal;
		}
		public float getDebtLimit1()
		{
		    return this.DebtLimit1;
		}
		public float getDebtAmount()
		{
		    return this.DebtAmount;
		}
		public int getIsPromotion()
		{
			return this.IsPromotion;
		}
		public int getIsRound()
		{
			return this.IsRound;
		}	
		public String getFFCashier()
		{
			return this.FFCashier;
		}		
		public String getBrokerCode()
		{
			return this.BrokerCode;
		}	
		public int getBrokerStatus()
		{
			return this.BrokerStatus;
		}
		public String getContractPerson()
		{
			return this.ContractPerson;
		}		
	    public int getIsCredit()
		{
			return this.IsCredit;
		}
		public int getIsCreditItem()
		{
			return this.IsCreditItem;
		}
		public int getCreditItemDay()
		{
			return this.CreditItemDay;
		}
		public String getPayment()
		{
			return this.Payment;
		}
		public String getTerms()
		{
			return this.Terms;
		}
		
		public ResultSet selectArFF() throws Exception {
			String StrSql = "SELECT [OID]," +
										"[LastModified]," +
										"[ModifyDate]," +
										"[ModifyTime]," +
										"[ModifiedBy]," +
										"[UserModify]," +
										"[CreatedDate]," +
										"[CreateDate]," +
										"[CreateTime]," +
										"[CreatedBy]," +
										"[UserCreate]," +
										"[IsActive]," +
										"[IsDeleted]," +
										
										"[ArCode],"+
										"[ArTitle],"+
										"[TitleName],"+
										"[ArName],"+
										"[ArNickName],"+
										
										"[ArAddr1],"+
										"[ArAddr2],"+
										"[TumbolCode],"+								  
										"[TumbolName],"+
										"[AmpurCode],"+		
										
										"[AmpurName],"+
										"[ProvinceCode],"+			
										"[ProvinceName],"+									  					  
										"[BillAdd1],"+
										"[BillAdd2],"+
										
										"[Telephone],"+
										"[Fax],"+
										"[Mobile],"+
										"[ArGroupOID],"+
										"[ArGroupCode],"+
										
										"[ArGroupDesc],"+
										"[ArGroupMainOID],"+
										"[ArGroupMainCode],"+
										"[ArGroupMainDesc],"+
										"[IsDisplayWeightDoc],"+
										
										"[ContactDate],"+
										"[tmpContactDate],"+
										"[FFSaleCode],"+
										"[SaleName],"+
										"[FFUserCode],"+
										
										"[CreatedBy],"+
										"[CreditDay],"+
										"[Remark],"+
										"[PicPath],"+
										"[ArCodeOld],"+
										
										"[ArStatus],"+
										"[DebtLimitBal]," +
										"[DebtLimit1]," +
										"[DebtAmount],"+
										"[IsPromotion],"+	
										
										"[IsRound],"+
										"[FFCashier],"+		
										"[BrokerCode],"+	
										"[BrokerName],"+
										"[BrokerStatus],"+	
										
										"[ContractPerson],"+	
										"[IsCredit],"+
										"[IsCreditItem],"+
										"[CreditItemDay],"+
										"[PaymentMethod],"+
										
										"[PaymentTerms]," +
										"[PaymentMethodDesc]," +
										"[PaymentTermsDesc]," +
										"[CarBandOID]," +
										"[VehicleRegistration]," +
										
										"[CarBandName],"+
										"[CarGenerationOID]," +
										"[CarType]," +
										"[ColorOID]," +
										"[CarSize]," +
										
										"[CarGenerationName]," +
										"[ColorName]," +
										"[CarGroup]," +
										"[CarGroupName] " +
						  						  
								"FROM	 [dbo].[udfArFF]() "+
								
								"WHERE	 [IsDeleted]='0' "; 
	 
			if (getStrParamArGroupMainCode()!=null) {
				StrSql += "AND [ArGroupMainOID] = '" + getStrParamArGroupMainCode() + "' ";
			}
			
			if (getStrParamArGroupCode()!=null) {
				StrSql += "AND [ArGroupOID] = '" + getStrParamArGroupCode() + "' ";
			}
	    	
			if (!(getStrParamArName().toString().equals(""))) {
				StrSql += "AND ([ArName] LIKE '%" + getStrParamArName() + "%' ";
			}
			
			if (!(getStrParamArName().toString().equals(""))) {
				StrSql += "OR [ArCode] LIKE '%" + getStrParamArName() + "%') ";
			}
			
			StrSql += "ORDER BY [ArCode] ASC ";
			
			return con.selectData(StrSql);
		 }

		public String OperationData(String OperationType) throws Exception
		{	
			try 
			{
				conn = con.Connect();		
				java.sql.CallableStatement cstmt = conn.prepareCall(
						"{call stpArFFManagement(" +
						"?,?,?,?,?, " +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?,?,?,?,?," +
						"?)}"
					);
			 if(conn != null)
			 {
				 /*
				 System.out.println(OperationType);
				 System.out.println(getOID());
				 System.out.println(getUsrOpt());
				 System.out.println(getIsActive());
				 System.out.println(getIsDeleted());
				 System.out.println(getArCode());
				 System.out.println(getArTitle());
				 System.out.println(getArName());
				 System.out.println(getArNickName());
				 System.out.println(getArAddr1());
				 System.out.println(getArAddr2());			
				 System.out.println(getTumbolCode());
				 System.out.println(getAmpurCode());
				 System.out.println(getProvinceCode());									
				 System.out.println(getBillAdd1());
				 System.out.println(getBillAdd2());		
				 System.out.println(getArGroupCode());
				 System.out.println(getTelephone());
				 System.out.println(getFax());
				 System.out.println(getMobile());
				 System.out.println(getFFSaleCode());
				 System.out.println(getFFUserCode());
				 System.out.println(getContactDate());
				 System.out.println(getCreditDay());
				 System.out.println(getRemark());
				 System.out.println(getIsDisplayWeightDoc());
				 System.out.println(getPicPath());
				 System.out.println(getArStatus());
				 System.out.println(getDebtLimitBal());
				 System.out.println(getDebtLimit1());
				 System.out.println(getDebtAmount());
				 System.out.println(getIsPromotion());	
				 System.out.println(getIsRound());	
				 System.out.println(getFFCashier());	
				 System.out.println(getBrokerCode());
				 System.out.println(getBrokerStatus());	
				 System.out.println(getContractPerson());	
				 System.out.println(getIsCredit());
				 System.out.println(getIsCreditItem());
				 System.out.println(getCreditItemDay());	
				 System.out.println(getPayment());	
				 System.out.println(getTerms());		
				 System.out.println(Types.VARCHAR); 
				 */
				 
				cstmt.setString( 1,OperationType);
				cstmt.setString( 2,getOID());
	            cstmt.setString( 3,getUsrOpt());
	            cstmt.setString( 4,getIsActive());
	            cstmt.setString( 5,getIsDeleted());
				cstmt.setString( 6,getArCode());
				cstmt.setString( 7,getArTitle());
				cstmt.setString( 8,getArName());
				cstmt.setString( 9,getArNickName());
				cstmt.setString(10,getArAddr1());
				cstmt.setString(11,getArAddr2());			
				cstmt.setString(12,getTumbolCode());
				cstmt.setString(13,getAmpurCode());
				cstmt.setString(14,getProvinceCode());									
				cstmt.setString(15,getBillAdd1());
				cstmt.setString(16,getBillAdd2());		
				cstmt.setString(17,getArGroupCode());
				cstmt.setString(18,getTelephone());
				cstmt.setString(19,getFax());
				cstmt.setString(20,getMobile());
				cstmt.setString(21,getFFSaleCode());
				cstmt.setString(22,getFFUserCode());
				cstmt.setString(23,getContactDate());
				cstmt.setInt(   24,getCreditDay());
				cstmt.setString(25,getRemark());
				cstmt.setString(26,getIsDisplayWeightDoc());
				cstmt.setString(27,getPicPath());
				cstmt.setInt(   28,getArStatus());
				cstmt.setFloat( 29,getDebtLimitBal());
				cstmt.setFloat( 30,getDebtLimit1());
				cstmt.setFloat( 31,getDebtAmount());
				cstmt.setInt(   32,getIsPromotion());	
				cstmt.setInt(   33,getIsRound());	
				cstmt.setString(34,getFFCashier());	
				cstmt.setString(35,getBrokerCode());
				cstmt.setInt(   36,getBrokerStatus());	
				cstmt.setString(37,getContractPerson());	
				cstmt.setInt(   38,getIsCredit());
				cstmt.setInt(   39,getIsCreditItem());
				cstmt.setInt(   40,getCreditItemDay());	
				cstmt.setString(41,getPayment());	
				cstmt.setString(42,getTerms());	
				cstmt.setString(43,getCarBandOID());
				cstmt.setString(44,getVehicleRegistration());
				cstmt.setString(45,getCarGenerationOID());
				cstmt.setString(46,getCarType());
				cstmt.setString(47,getColorOID());
				cstmt.setString(48,getCarSize());
				cstmt.setString(49,getCompanyOID());
				cstmt.setString(50,getCarGroup());
				
				cstmt.registerOutParameter(51, Types.VARCHAR); 
				
				cstmt.execute();
				
				return cstmt.getString(51);
	           }
			} catch (Exception e) {
	            e.printStackTrace();
	        } finally {
	            if (conn != null) {
	            	conn.close();
	            }
	        }
	        return null;

		}
		
		public void closeConnecttion() throws Exception {
			conn.close();
	    }
		
		public void DEFINE_ArFF() {
			rs = null;
			
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			try {
				rs = selectArFF();
				while (rs.next()) {
					ContentValues Val = new ContentValues();
					Val.put("ArFFOID", rs.getString("OID"));

					Val.put("ArCode", rs.getString("ArCode"));
					Val.put("ArTitle", rs.getString("ArTitle"));
					Val.put("TitleName", rs.getString("TitleName"));
					Val.put("ArName", rs.getString("ArName"));

					Val.put("ArNickName", rs.getString("ArNickName"));
					Val.put("ArAddr1", rs.getString("ArAddr1"));
					Val.put("ArAddr2", rs.getString("ArAddr2"));
					Val.put("TumbolCode", rs.getString("TumbolCode"));
					Val.put("TumbolName", rs.getString("TumbolName"));

					Val.put("AmpurCode", rs.getString("AmpurCode"));
					Val.put("AmpurName", rs.getString("AmpurName"));
					Val.put("ProvinceCode", rs.getString("ProvinceCode"));
					Val.put("ProvinceName", rs.getString("ProvinceName"));
					Val.put("BillAdd1", rs.getString("BillAdd1"));

					Val.put("BillAdd2", rs.getString("BillAdd2"));
					Val.put("Telephone", rs.getString("Telephone"));
					Val.put("Fax", rs.getString("Fax"));
					Val.put("Mobile", rs.getString("Mobile"));
					Val.put("ArGroupOID", rs.getString("ArGroupOID"));

					Val.put("ArGroupCode", rs.getString("ArGroupCode"));
					Val.put("ArGroupDesc", rs.getString("ArGroupDesc"));
					Val.put("ArGroupMainOID", rs.getString("ArGroupMainOID"));
					Val.put("ArGroupMainCode", rs.getString("ArGroupMainCode"));
					Val.put("ArGroupMainDesc", rs.getString("ArGroupMainDesc"));

					Val.put("IsDisplayWeightDoc",
							rs.getString("IsDisplayWeightDoc"));
					Val.put("ContactDate", rs.getString("ContactDate"));
					Val.put("tmpContactDate", rs.getString("tmpContactDate"));
					Val.put("FFSaleCode", rs.getString("FFSaleCode"));
					Val.put("SaleName", rs.getString("SaleName"));

					Val.put("FFUserCode", rs.getString("FFUserCode"));
					Val.put("CreatedBy", rs.getString("CreatedBy"));
					Val.put("CreditDay", rs.getString("CreditDay"));
					Val.put("Remark", rs.getString("Remark"));
					Val.put("PicPath", rs.getString("PicPath"));

					Val.put("ArCodeOld", rs.getString("ArCodeOld"));
					Val.put("ArStatus", rs.getString("ArStatus"));
					Val.put("DebtLimitBal", rs.getString("DebtLimitBal"));
					Val.put("DebtLimit1", rs.getString("DebtLimit1"));
					Val.put("DebtAmount", rs.getString("DebtAmount"));

					Val.put("IsPromotion", rs.getString("IsPromotion"));
					Val.put("IsRound", rs.getString("IsRound"));
					Val.put("FFCashier", rs.getString("FFCashier"));
					Val.put("BrokerCode", rs.getString("BrokerCode"));
					Val.put("BrokerName", rs.getString("BrokerName"));

					Val.put("BrokerStatus", rs.getString("BrokerStatus"));
					Val.put("ContractPerson", rs.getString("ContractPerson"));
					Val.put("IsCredit", rs.getString("IsCredit"));
					Val.put("IsCreditItem", rs.getString("IsCreditItem"));
					Val.put("CreditItemDay", rs.getString("CreditItemDay"));

					Val.put("PaymentMethod", rs.getString("PaymentMethod"));
					Val.put("PaymentTerms", rs.getString("PaymentTerms"));
					Val.put("PaymentMethodDesc", rs.getString("PaymentMethodDesc"));
					Val.put("PaymentTermsDesc", rs.getString("PaymentTermsDesc"));
					Val.put("CarBandOID", rs.getString("CarBandOID"));

					Val.put("VehicleRegistration",rs.getString("VehicleRegistration"));
					Val.put("CarBandName", rs.getString("CarBandName"));
					Val.put("CarGenerationOID", rs.getString("CarGenerationOID"));
					Val.put("CarType", rs.getString("CarType"));
					Val.put("ColorOID", rs.getString("ColorOID"));

					Val.put("CarSize", rs.getString("CarSize"));
					Val.put("CarGenerationName", rs.getString("CarGenerationName"));
					Val.put("ColorName", rs.getString("ColorName"));
					Val.put("CarGroup", rs.getString("CarGroup"));
					Val.put("CarGroupName", rs.getString("CarGroupName"));

					db.insert(TABLE_ArFF, null, Val);
				}
			} catch (Exception e) {
				Log.d("TABLE_ArFF", "Create Table not Successfully.");
			}finally{
				try {
					closeConnecttion();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			Log.d("TABLE_ArFF", "Create Table Successfully.");
			db.close();
		}
		
		public String[][] SelectAll_ArFF(String OID,String Datetime) throws Exception {
			try {
				String arrData[][] = null;
				
				myDb = new SQLiteDBClass(getContext());
				db = myDb.getWritableDatabase();
				
				String strSQL = "SELECT  ArFFOID As _id , * FROM "
						+ TABLE_ArFF;
				
				if (!OID.equals("")) {
					strSQL += " WHERE [ArFFOID] LIKE '" + OID + "' ";
				}
				if (!Datetime.equals("")) {
					strSQL += " WHERE [ArCode] LIKE '%" + Datetime + "%' ";
				}
				strSQL += " ORDER BY [ArCode] ASC ";
				Cursor cursor = db.rawQuery(strSQL, null);
				if (cursor != null) {
					if (cursor.moveToFirst()) {
						arrData = new String[cursor.getCount()][cursor
								.getColumnCount()];
						int i = 0;
						do {
							arrData[i][0] = cursor.getString(1);

							arrData[i][1] = cursor.getString(2);
							arrData[i][2] = cursor.getString(3);
							arrData[i][3] = cursor.getString(4);
							arrData[i][4] = cursor.getString(5);
							arrData[i][5] = cursor.getString(6);

							arrData[i][6] = cursor.getString(7);
							arrData[i][7] = cursor.getString(8);
							arrData[i][8] = cursor.getString(9);
							arrData[i][9] = cursor.getString(10);
							arrData[i][10] = cursor.getString(11);

							arrData[i][11] = cursor.getString(12);
							arrData[i][12] = cursor.getString(13);
							arrData[i][13] = cursor.getString(14);
							arrData[i][14] = cursor.getString(15);
							arrData[i][15] = cursor.getString(16);

							arrData[i][16] = cursor.getString(17);
							arrData[i][17] = cursor.getString(18);
							arrData[i][18] = cursor.getString(19);
							arrData[i][19] = cursor.getString(20);
							arrData[i][20] = cursor.getString(21);
							
							arrData[i][21] = cursor.getString(22);
							arrData[i][22] = cursor.getString(23);
							arrData[i][23] = cursor.getString(24);
							arrData[i][24] = cursor.getString(25);
							arrData[i][25] = cursor.getString(26);
							
							arrData[i][26] = cursor.getString(27);
							arrData[i][27] = cursor.getString(28);
							arrData[i][28] = cursor.getString(29);
							arrData[i][29] = cursor.getString(30);
							arrData[i][30] = cursor.getString(31);
							
							arrData[i][54] = cursor.getString(55);
							
							arrData[i][55] = cursor.getString(56);
							arrData[i][56] = cursor.getString(57);
							arrData[i][57] = cursor.getString(58);
							arrData[i][58] = cursor.getString(59);
							arrData[i][59] = cursor.getString(60);
							arrData[i][60] = cursor.getString(61);
							
							arrData[i][61] = cursor.getString(62);
							arrData[i][62] = cursor.getString(63);
							arrData[i][63] = cursor.getString(64);
							arrData[i][64] = cursor.getString(65);

							i++;
						} while (cursor.moveToNext());
					}
				}
				cursor.close();

				return arrData;

			} catch (Exception e) {
				return null;
			}
		}
		
		public long InsertArFF(
				String ArFFOID,
				

				String ArCode, 
				String ArName, 
				String ProvinceCode, 
				String ProvinceName,
				String Telephone, 
				
				String Mobile, 
				String ArGroupOID, 
				String ArGroupCode,
				String ArGroupDesc,
				String ArGroupMainOID, 
				
				String ArGroupMainCode, 
				String ArGroupMainDesc, 
				String FFSaleCode,
				String SaleName,
				String FFUserCode,
				
				String CreatedBy,
				String PicPath,
				String ArStatus,
				String CarBandOID,
				String VehicleRegistration,
				
				String CarBandName,
				String CarGenerationOID,
				String CarType,
				String ColorOID,
				String CarSize,
				
				String CarGenerationName,
				String ColorName,
				String CarGroup,
				String CarGroupName,
				
				String UserModify, 
				String CreateTime,
				String LastUpdate, 
				String StatusUpdate,
				String IsFavorite) {
					
			// TODO Auto-generated method stub

			try {
				myDb = new SQLiteDBClass(getContext());
				db = myDb.getWritableDatabase();
				
				ContentValues Val = new ContentValues();
				Val.put("ArFFOID", ArFFOID);

				Val.put("ArCode", ArCode);
				Val.put("ArName", ArName);
				
				Val.put("ProvinceCode", ProvinceCode);
				Val.put("ProvinceName", ProvinceName);
				
				Val.put("Telephone", Telephone);
				Val.put("Mobile", Mobile);
				Val.put("ArGroupOID", ArGroupOID);
				Val.put("ArGroupCode", ArGroupCode);
				
				Val.put("ArGroupDesc", ArGroupDesc);
				Val.put("ArGroupMainOID", ArGroupMainOID);
				Val.put("ArGroupMainCode", ArGroupMainCode);
				Val.put("ArGroupMainDesc", ArGroupMainDesc);
				
				Val.put("FFSaleCode", FFSaleCode);
				Val.put("SaleName", SaleName);
				Val.put("FFUserCode", FFUserCode);
				
				Val.put("CreatedBy", CreatedBy);
				
				Val.put("PicPath", PicPath);
				
				Val.put("CarBandOID", CarBandOID);
				Val.put("VehicleRegistration", VehicleRegistration);
				
				Val.put("CarBandName", CarBandName);
				Val.put("CarGenerationOID", CarGenerationOID);
				Val.put("CarType", CarType);
				
				Val.put("ColorOID", ColorOID);
				Val.put("CarSize", CarSize);
				Val.put("CarGenerationName", CarGenerationName);
				Val.put("ColorName", ColorName);
				Val.put("CarGroup", CarGroup);
				
				Val.put("CarGroupName", CarGroupName);
				
				Val.put("ColorOID", ColorOID);
				Val.put("CarSize", CarSize);
				Val.put("CarGenerationName", CarGenerationName);
				Val.put("ColorName", ColorName);
				Val.put("CarGroup", CarGroup);
				
				Val.put("UserModify", UserModify);
				Val.put("CreateTime", CreateTime);
				Val.put("LastUpdate", LastUpdate);
				Val.put("StatusUpdate", StatusUpdate);
				Val.put("IsFavorite", IsFavorite);

				long rows = db.insert(TABLE_ArFF, null, Val);

				db.close();
				return rows; // return rows inserted.

			} catch (Exception e) {
				return -1;
			}

		}
		
		public long UpdateArFF(
				String ArFFOID,
				
				String ArCode, 
				String ArName, 
				String ProvinceCode, 
				String ProvinceName,
				String Telephone, 
				
				String Mobile, 
				String ArGroupOID, 
				String ArGroupCode,
				String ArGroupDesc,
				String ArGroupMainOID,
				
				String ArGroupMainCode, 
				String ArGroupMainDesc, 
				String FFSaleCode,
				String SaleName,
				String FFUserCode,
			
				String Remark,
				String PicPath,
				String ArStatus,
				String CarBandOID,
				String VehicleRegistration,
				
				String CarBandName,
				String CarGenerationOID,
				String CarType,
				String ColorOID,
				String CarSize,
				
				String CarGenerationName,
				String ColorName,
				String CarGroup,
				String CarGroupName,
				
				String UserModify, 
				String LastUpdate, 
				String StatusUpdate) {
					
			// TODO Auto-generated method stub

			try {
				myDb = new SQLiteDBClass(getContext());
				db = myDb.getWritableDatabase();
				
				ContentValues Val = new ContentValues();
				Val.put("ArFFOID", ArFFOID);

				Val.put("ArCode", ArCode);
				Val.put("ArName", ArName);
				
				Val.put("ProvinceCode", ProvinceCode);
				Val.put("ProvinceName", ProvinceName);
				
				Val.put("Telephone", Telephone);
				Val.put("Mobile", Mobile);
				Val.put("ArGroupOID", ArGroupOID);
				Val.put("ArGroupCode", ArGroupCode);
				
				Val.put("ArGroupDesc", ArGroupDesc);
				Val.put("ArGroupMainOID", ArGroupMainOID);
				Val.put("ArGroupMainCode", ArGroupMainCode);
				Val.put("ArGroupMainDesc", ArGroupMainDesc);
				
				Val.put("FFSaleCode", FFSaleCode);
				Val.put("SaleName", SaleName);
				Val.put("FFUserCode", FFUserCode);
				
			
				Val.put("Remark", Remark);
				Val.put("PicPath", PicPath);
				
				Val.put("ArStatus", ArStatus);

				
				Val.put("CarBandOID", CarBandOID);
				Val.put("VehicleRegistration", VehicleRegistration);
				
				Val.put("CarBandName", CarBandName);
				Val.put("CarGenerationOID", CarGenerationOID);
				Val.put("CarType", CarType);
				
				Val.put("ColorOID", ColorOID);
				Val.put("CarSize", CarSize);
				Val.put("CarGenerationName", CarGenerationName);
				Val.put("ColorName", ColorName);
				Val.put("CarGroup", CarGroup);
				
				Val.put("CarGroupName", CarGroupName);
				
				Val.put("ColorOID", ColorOID);
				Val.put("CarSize", CarSize);
				Val.put("CarGenerationName", CarGenerationName);
				Val.put("ColorName", ColorName);
				Val.put("CarGroup", CarGroup);
				
				Val.put("UserModify", UserModify);
				Val.put("LastUpdate", LastUpdate);
				Val.put("StatusUpdate", StatusUpdate);

//				long rows = db.update(TABLE_ArFF, null, Val);
				long rows = db.update(TABLE_ArFF, Val, " ArCode = ?",
						new String[] { String.valueOf(ArCode) });
				db.close();
				return rows; // return rows inserted.

			} catch (Exception e) {
				return -1;
			}
		}
		
}
